//
//  BoJianVeiwController.m
//  jinwang
//
//  Created by jzb on 2018/2/28.
//  Copyright © 2018年 jzb. All rights reserved.
//

#import "BoJianVeiwController.h"
#import "ReleaseBoJianVC.h"
#import "DynamicVC.h"
#import "BJHotListVC.h"
#import "JWBJSiftView.h"

@interface BoJianVeiwController ()
{
    
    JWBJSiftView *JSiftView;
}
//相机
@property (nonatomic,strong) UIButton *photoBtn;
//筛选
@property (nonatomic,strong) UIButton *shaixuanBtn;

@property (nonatomic, strong) MLMSegmentHead *segHead;
@property (nonatomic, strong) MLMSegmentScroll *segScroll;
@property (nonatomic, strong) TYAlertController *alertController;

@end

@implementation BoJianVeiwController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
//    self.title = @"我的博见";
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"back_common"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(goBack)];
    UIBarButtonItem *photoItem = [[UIBarButtonItem alloc]initWithCustomView:self.photoBtn];
    
    self.navigationItem.leftBarButtonItems = @[backItem,photoItem];
    
    UIBarButtonItem *shaixuanItem = [[UIBarButtonItem alloc]initWithCustomView:self.shaixuanBtn];
    self.navigationItem.rightBarButtonItem = shaixuanItem;
    
    UIView *TitleBGView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 120, 44)];
    
//    TitleBGView.backgroundColor = [UIColor orangeColor];
    
    NSArray *list = @[@"动态",@"热榜"];
    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(0, 0, TitleBGView.width, 44) titles:list headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutDefault];
//    _segHead.fontScale = 1.1;
    _segHead.fontSize = 17;
    _segHead.deSelectColor = [UIColor whiteColor];
    _segHead.selectColor = kRGBColor(80, 80, 80);
    _segHead.lineScale = .7;
    _segHead.bottomLineHeight = 0;
    _segHead.lineColor = kRGBColor(80, 80, 80);
    _segHead.headColor = [UIColor clearColor];
    
    _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-CGRectGetMaxY(_segHead.frame)-20) vcOrViews:[self vcArr:list.count]];
    
    _segScroll.loadAll = YES;
    _segScroll.showIndex = 0;
    
    _segScroll.backgroundColor = [UIColor whiteColor];
    
    [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
        
        [TitleBGView addSubview:_segHead];
        [self.view addSubview:_segScroll];
        self.navigationItem.titleView = TitleBGView;
//        [self.navigationItem.titleView addSubview:_segHead];
        
    }];
    
    JSiftView = [[JWBJSiftView alloc]initWithFrame:CGRM(0, 0, 750-80, 1334-340)];
    
    JSiftView.layer.cornerRadius = 5.0;
    JSiftView.layer.masksToBounds = YES;
}


#pragma mark -懒加载
- (UIButton *)photoBtn{
    if (!_photoBtn) {
        _photoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _photoBtn.frame = CGRectMake(0, 0, 44, 44);
        [_photoBtn setImage:[UIImage imageNamed:@"jw_bojian_camera"] forState:UIControlStateNormal];
        [_photoBtn addTarget:self action:@selector(photoButOnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _photoBtn;
}
#pragma mark -懒加载
- (UIButton *)shaixuanBtn{
    if (!_shaixuanBtn) {
        _shaixuanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _shaixuanBtn.frame = CGRectMake(0, 0, 44, 44);
        [_shaixuanBtn setImage:[UIImage imageNamed:@"jw_bojian_shaixuan"] forState:UIControlStateNormal];
        [_shaixuanBtn addTarget:self action:@selector(shaixuanBtnOnclick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _shaixuanBtn;
}
- (void)photoButOnclick:(UIButton *)sender{
    BOOL isLogin = [[ToolManager sharedManager] checkLoginStateAtVC:self];
    
    if (isLogin) {
        ReleaseBoJianVC *VC = [ReleaseBoJianVC new];
        
        [self.navigationController pushViewController:VC animated:YES];
    }
    
}
- (void)shaixuanBtnOnclick:(UIButton *)sender{
    JSiftView.frame = CGRM(0, 0, 750-80, 1334-340);
    _alertController = [TYAlertController alertControllerWithAlertView:JSiftView preferredStyle:TYAlertControllerStyleAlert];
    
    [self presentViewController:_alertController animated:YES completion:nil];
    __weak __typeof(self) weakSelf = self;
    JSiftView.siftDateBlcok = ^(BOOL IsSift, NSString *user_sex, NSString *user_active, NSString *region_id, NSString *user_age, NSString *user_hobby, NSString *user_occupation, NSString *user_type, NSString *user_rank) {
        
        [weakSelf.alertController.view hideView];
        if (IsSift) {
            
            NSMutableDictionary *dict =[[NSMutableDictionary alloc] init];
            [dict setValue:user_sex forKey:@"user_sex"];
            [dict setValue:user_active forKey:@"user_active"];
            [dict setValue:region_id forKey:@"region_id"];
            [dict setValue:user_age forKey:@"user_age"];
            [dict setValue:user_hobby forKey:@"user_hobby"];
            [dict setValue:user_occupation forKey:@"user_occupation"];
            [dict setValue:user_type forKey:@"user_type"];
            [dict setValue:user_rank forKey:@"user_rank"];
            
            // 2.创建通知
            NSNotification *notification =[NSNotification notificationWithName:@"JWBJSiftNotification" object:nil userInfo:dict];
            
            // 3.通过 通知中心 发送 通知
            [[NSNotificationCenter defaultCenter] postNotification:notification];            
        }
    };
}
#pragma mark - 数据源
- (NSArray *)vcArr:(NSInteger)count {
    NSMutableArray *arr = [NSMutableArray array];
    DynamicVC *Dynamic_VC = [[DynamicVC alloc]init];
    BJHotListVC *BJHotList_VC = [[BJHotListVC alloc]init];
    
    [arr addObject:Dynamic_VC];
    [arr addObject:BJHotList_VC];

    return arr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
